package sz;

import pojo.entity.Person;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class GetMethod {
    public static void main(String[] args) {
        try {
            Class cls=Class.forName("pojo.entity.Person");
            Person person= (Person) cls.newInstance();
            // 调用实例方法
            Method method=cls.getDeclaredMethod("getAge");
            System.out.println(method.invoke(person));

            // 调用静态方法
            method=cls.getDeclaredMethod("silentMethod");
            method.setAccessible(true);
            method.invoke(person);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
